package com.cityfood.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cityfood.common.pojo.CityFoodResult;
import com.cityfood.pojo.CfAttributeKey;
import com.cityfood.pojo.CfAttributeValue;
import com.cityfood.service.AttributeKeyService;
import com.cityfood.service.AttributeValueService;

@Controller
public class AttributeController {
	
	@Autowired
	private AttributeKeyService keyService;
	
	@Autowired
	private AttributeValueService valueService;
	
	//后台管理---------------------------------------------------------------------------
	
	/**
	 * 根据类目主键categoryId获取属性key
	 */
	@RequestMapping(value="/attribute/key",method=RequestMethod.GET)
	@ResponseBody
	public CityFoodResult getAttributeKeyByCategoryId(Integer categoryId){
		CityFoodResult cityfoodResult = new CityFoodResult();
		List<CfAttributeKey> list = keyService.getAttributeKey(categoryId);
		if (list!=null) {
			cityfoodResult.setCode(200);
			cityfoodResult.setMsg("获取属性key成功");
			cityfoodResult.setData(list);
			return cityfoodResult;
		}else{
			cityfoodResult.setCode(201);
			cityfoodResult.setMsg("获取属性key失败");
			cityfoodResult.setData("{}");
			return cityfoodResult;
		}
	}
	
	/**
	 * 根据keyId获取属性value
	 */
	@RequestMapping(value="/attribute/value",method=RequestMethod.GET)
	@ResponseBody
	public CityFoodResult getAttributeValueByKeyId(Integer keyId){
		CityFoodResult cityfoodResult = new CityFoodResult();
		List<CfAttributeValue> list = valueService.getAttributeValue(keyId);
		if (list!=null) {
			cityfoodResult.setCode(200);
			cityfoodResult.setMsg("获取属性value成功");
			cityfoodResult.setData(list);
			return cityfoodResult;
		}else{
			cityfoodResult.setCode(201);
			cityfoodResult.setMsg("获取属性value失败");
			cityfoodResult.setData("{}");
			return cityfoodResult;
		}
	}

}
